Page({
  data: {
    activityInfo: {},
    participantsList: []
  },

  onLoad(options) {
    // 模拟获取活动详情
    this.setData({
      activityInfo: {
        id: options.id || 1,
        title: '太极拳晨练活动',
        time: '2024-01-20 06:00-07:00',
        location: '社区广场',
        participants: 28,
        image: 'https://dummyimage.com/800x600/eeeeee/aaaaaa.png&text=activity',
        content: '太极拳是中国传统的健身运动，具有调节身心、强身健体的功效。本次活动由专业教练带领，适合各年龄段的老年朋友参加。活动内容包括基础太极拳动作教学、呼吸调节练习等。欢迎大家积极参与！',
        joined: false,
        organizer: {
          name: '社区活动中心',
          avatar: 'https://dummyimage.com/120x120/cccccc/888888.png&text=Org'
        }
      },
      participantsList: [
        { id: 1, avatar: 'https://dummyimage.com/120x120/cccccc/888888.png&text=A1' },
        { id: 2, avatar: 'https://dummyimage.com/120x120/cccccc/888888.png&text=A2' },
        { id: 3, avatar: 'https://dummyimage.com/120x120/cccccc/888888.png&text=A3' },
        { id: 4, avatar: 'https://dummyimage.com/120x120/cccccc/888888.png&text=A4' },
        { id: 5, avatar: 'https://dummyimage.com/120x120/cccccc/888888.png&text=A5' }
      ]
    });
  },

  onJoin() {
    const joined = this.data.activityInfo.joined;
    const participants = this.data.activityInfo.participants;

    wx.showModal({
      title: joined ? '取消报名' : '报名确认',
      content: joined ? '确定要取消报名吗？' : '确定要报名参加该活动吗？',
      success: (res) => {
        if (res.confirm) {
          this.setData({
            'activityInfo.joined': !joined,
            'activityInfo.participants': joined ? participants - 1 : participants + 1
          });
          wx.showToast({
            title: joined ? '已取消报名' : '报名成功',
            icon: 'success'
          });
        }
      }
    });
  },

  onShareAppMessage() {
    return {
      title: this.data.activityInfo.title,
      path: `/pages/community/activity/activity?id=${this.data.activityInfo.id}`
    };
  }
})
